import React, { Component } from "react";
export default class Count extends Component {
  add = () => {
    const { value } = this.selectNum;
    this.props.createIncrementAction(value * 1);
  };
  subtract = () => {
    const { value } = this.selectNum;
    this.props.createDecrementAction(value * 1);
  };
  addAndOdd = () => {
    const { value } = this.selectNum;
    if (this.props.count % 2 === 0) {
      this.props.createIncrementAction(value * 1);
    }
  };
  asyncAdd = () => {
    const { value } = this.selectNum;
    this.props.createIncrementAsyncAction(value * 1, 1000);
  };
  render() {
    // const { count } = this.state;
    const { count } = this.props;
    return (
      <div>
        <h1>Count的值是:{count}</h1>
        <select ref={(c) => (this.selectNum = c)}>
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
        </select>
        <button onClick={this.add}>+</button>
        <button onClick={this.subtract}>-</button>
        <button onClick={this.addAndOdd}>oddAdd</button>
        <button onClick={this.asyncAdd}>asyncAdd</button>
      </div>
    );
  }
}

